package com.qfedu.mavenk.ioc;

import com.qfedu.mavenk.di.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc: 测试bean注入依赖类的属性数据
 * @datatime: 2022/10/18 10:26
 */
public class Test {
    public static void main(String[] args) {
        //读取配置文件    ClassPathXmlApplicationContext加载spring的xml配置文件
        ApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("spring-context.xml");
        //通过bean唯一标识id值来获取xml配置文件中的数据注入,也就是已经注册实例化的bean
        User user = (User) classPathXmlApplicationContext.getBean("user");
        System.out.println(user.toString());
        ((ClassPathXmlApplicationContext)classPathXmlApplicationContext).close();
    }
}
